/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ortus;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import sage.*;
import sagex.api.MediaFileAPI;
/**
 *
 * @author jphipps
 */
public class SageMediaObject extends ortusvars {

	Object mo = null;
	int mediaid = 0;
	String mediatitle ="";
	String episodetitle = "";
	String mediapath = "";
	String Description = "";
	String mediaencoding = "";
	int mediatype = 0;
	int mediagroup = 0;
	long mediasize = 0;
	long mediaduration =0;
	long lastwatched = 0;
	long airingstarttime= 0;
	float userrating = 0;
	String mpaarated = "";
	HashMap<String,List> fanart = new HashMap<String,List>();

	public SageMediaObject(Object o){
		mo = o;
	}
	
	public Object SageCall(String sagemethod) {
		try {
			return sage.SageTV.api(sagemethod, new Object[]{mo});
		} catch (InvocationTargetException ex) {
			ortus.api.DebugLog(ERROR, "SageCall: Exception: " + ex);
			return null;
		}
	}

	public void AddFanart(String fanarttype, String file) {
		if ( fanart.get(fanarttype) != null) {
			fanart.get(fanarttype).add(file);
			fanart.put(fanarttype,fanart.get(fanarttype));
		} else {
			List x = new ArrayList();
			x.add(file);
			fanart.put(fanarttype, x);
		}

	}

	public Object[] GetFanart(String fanarttype) {
		if( fanart.get(fanarttype) == null)
			return new Object[] {};
		else
			return fanart.get(fanarttype).toArray();
	}

	public int GetMediaId() {
		return MediaFileAPI.GetMediaFileID(mo);
	}

	public String GetMediaTitle() {
		return mediatitle;
	}
	public void SetMediaTitle(String mediatitle) {
		this.mediatitle = mediatitle;
	}

	public String GetEpisodeTitle() {
		return episodetitle;
	}
	public void SetEpisodeTitle(String episodetitle) {
		this.episodetitle = episodetitle;
	}

	public String GetMediaPath() {
		return mediapath;
	}
	public void SetMediaPath(String mediapath) {
		this.mediapath = mediapath;
	}

	public String GetDescription() {
		return Description;
	}
	public void SetDescription(String Description) {
		this.Description = Description;
	}

	public String GetMediaEncoding() {
		return mediaencoding;
	}
	public void SetMediaEncoding(String mediaencoding) {
		this.mediaencoding = mediaencoding;
	}

	public int GetMediaType() {
		return mediatype;
	}
	public void SetMediaType(int mediatype) {
		this.mediatype = mediatype;
	}

	public boolean IsTV() {
		if ( mediatype == 1 || mediatype == 3)
			return true;
		else
			return false;
	}
	public boolean IsMovie() {
		if ( mediatype == 2)
			return true;
		else
			return false;
	}
	public boolean IsRecording() {
		if ( mediagroup == 0)
			return true;
		else
			return false;
	}
	public int GetMediaGroup() {
		return mediagroup;
	}
	public void SetMediaGroup(int mediagroup) {
		this.mediagroup = mediagroup;
	}

	public long GetAiringStartTime() {
		return airingstarttime;
	}
	public void SetAiringStartTime(long airingstartttime) {
		this.airingstarttime = airingstarttime;
	}

	public float GetUserRating() {
		return userrating;
	}
	public void SetUerRating(float userrating) {
		this.userrating = userrating;
	}

	public String GetMPAARated() {
		return mpaarated;
	}
	public void SetMPAARated(String mpaarated) {
		this.mpaarated = mpaarated;
	}

}
